package com.cqh.recruit.controller.school;

import com.cqh.recruit.result.Result;
import com.cqh.recruit.service.IDashboardService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Dashboard 统计数据控制器
 *
 * @author dh
 * @since 2025-10-28
 * @version v1.0
 */
@RestController("schoolDashboardController")
@RequestMapping("/api/school/dashboard")
public class DashboardController {

    @Autowired
    private IDashboardService dashboardService;

    @GetMapping("/stats")
    @Operation(summary = "获取仪表盘统计数据")
    public Result getStats() {
        try {
            Map<String, Object> stats = dashboardService.getDashboardStats();
            return Result.buildSuccess(stats);
        } catch (Exception e) {
            return Result.buildFail(5001, "获取统计数据失败：" + e.getMessage());
        }
    }

    @GetMapping("/activity-status")
    @Operation(summary = "获取活动状态分布")
    public Result getActivityStatusDistribution() {
        try {
            Map<String, Object> statusStats = dashboardService.getActivityStatusDistribution();
            return Result.buildSuccess(statusStats);
        } catch (Exception e) {
            return Result.buildFail(5001, "获取活动状态分布失败：" + e.getMessage());
        }
    }

    @GetMapping("/monthly-trends")
    @Operation(summary = "获取本月数据趋势")
    public Result getMonthlyTrends() {
        try {
            Map<String, Object> trends = dashboardService.getMonthlyTrends();
            return Result.buildSuccess(trends);
        } catch (Exception e) {
            return Result.buildFail(5001, "获取月度趋势数据失败：" + e.getMessage());
        }
    }

    @GetMapping("/enrollment-stats")
    @Operation(summary = "获取报名统计数据")
    public Result getEnrollmentStats() {
        try {
            Map<String, Object> enrollmentStats = dashboardService.getEnrollmentStats();
            return Result.buildSuccess(enrollmentStats);
        } catch (Exception e) {
            return Result.buildFail(5001, "获取报名统计数据失败：" + e.getMessage());
        }
    }
}
